﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SetTitleMatchMode - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SetTitleMatchMode function sets the matching behavior of the WinTitle parameter in built-in functions such as WinWait." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SetTitleMatchMode</h1>

<p>Sets the matching behavior of the WinTitle parameter in built-in functions such as <a href="WinWait.htm">WinWait</a>.</p>

<pre class="Syntax">
<span class="func">SetTitleMatchMode</span> MatchMode
<span class="func">SetTitleMatchMode</span> Speed
</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>MatchMode</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#strings">字符串</a></p>
      <p>One of the following digits or the word RegEx:</p>
      <p><strong>1</strong>: A window's title must start with the specified <em>WinTitle</em> to be  a match.<br>
        <strong>2</strong>: A window's title can contain <em>WinTitle</em> anywhere inside it to be a match. <br>
      <strong>3</strong>:  A window's title must exactly match <em>WinTitle</em> to be a match.</p>
      <p id="RegEx"><strong>"RegEx"</strong>: Changes <em>WinTitle</em>, <em>WinText</em>, <em>ExcludeTitle</em>, and <em>ExcludeText</em> to accept <a href="../misc/RegEx-QuickRef.htm">regular expressions</a>. 例如: <code><a href="WinActivate.htm">WinActivate</a> "Untitled.*Notepad"</code>.</p>
      <p>Note:</p>
      <ul>
        <li>RegEx also applies to <a href="../misc/WinTitle.htm#ahk_class">ahk_class</a> and <a href="../misc/WinTitle.htm#ahk_exe">ahk_exe</a>; 例如, <code>ahk_class IEFrame</code> searches for any window whose class name contains <em>IEFrame</em> anywhere (this is because by default, regular expressions find a match <em>anywhere</em> in the target string).</li>
        <li>For <em>WinTitle</em>, each component is separate. 例如, in <code>"i)^untitled ahk_class i)^notepad$ ahk_pid " mypid</code>, <code>i)^untitled</code> and <code>i)^notepad$</code> are separate regex patterns and <code>mypid</code> is always compared numerically (it is not a regex pattern).</li>
        <li>For <em>WinText</em>, each text element (i.e. each control's text) is matched against the RegEx separately.  Therefore, it is not possible to have a match span more than one text element.</li>
      </ul>
      <p>The modes above also affect <em>ExcludeTitle</em> in the same way as <em>WinTitle</em>. 例如, mode 3 requires that a window's title exactly match <em>ExcludeTitle</em> for that window to be excluded.</p>
  </dd>

  <dt>Speed</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>One of the following words to specify how the <em>WinText</em> and <em>ExcludeText</em> parameters should be matched:</p>
    <p><strong>Fast</strong>: This is the default behavior. Performance may be substantially better than <em>Slow</em>, but certain types of controls are not detected. For instance, text is typically detected within Static and Button controls, but not Edit controls, unless they are owned by the script.</p>
    <p><strong>Slow</strong>: Can be much slower, but works with all controls which respond to the <a href="https://msdn.microsoft.com/en-us/library/ms632627">WM_GETTEXT</a> message.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>This function affects the behavior of all windowing functions, e.g. <a href="WinExist.htm">WinExist</a> and <a href="WinActivate.htm">WinActivate</a>. <a href="WinGetText.htm">WinGetText</a> is affected in the same way as other functions, but it always uses the <em>Slow</em> method to retrieve text.</p>
<p>If unspecified, TitleMatchMode defaults to 2 and <em>fast</em>.</p>
<p>If a <a href="../misc/WinTitle.htm#ahk_group">window group</a> is used, the current title match mode applies to each individual rule in the group.</p>
<p>Generally, the <em>slow</em> mode should be used only if the  target window cannot be uniquely identified by its title and <em>fast</em>-mode text. This is because the slow mode can be extremely slow if there are any application windows that are busy or &quot;not responding&quot;.</p>
<p>Window Spy has an option for <em>Slow TitleMatchMode</em> so that its easy to determine whether the <em>Slow</em> mode is needed.</p>
<p>If you wish to change both attributes, run the function twice as in this example:</p>
<pre>SetTitleMatchMode 2
SetTitleMatchMode "slow"</pre>
<p>The built-in variables <strong>A_TitleMatchMode</strong> and <strong>A_TitleMatchModeSpeed</strong> contain the current settings.</p>
<p>Regardless of the current TitleMatchMode, <em>WinTitle</em>, <em>WinText</em>, <em>ExcludeTitle</em> and <em>ExcludeText</em> are case sensitive. The only exception is the <a href="../misc/RegEx-QuickRef.htm#Options">case-insensitive option</a> of the RegEx mode; 例如: <code><strong>i)</strong>untitled - notepad</code>.</p>
<p>每个新运行的<a href="../misc/Threads.htm">线程</a>(如 <a href="../Hotkeys.htm">热键</a>, <a href="../objects/Menu.htm">自定义菜单项</a>或<a href="SetTimer.htm">定时</a>子程序) 都会以此函数的默认设置开始. 这个默认设置可以通过在脚本的自动执行段(脚本的顶部) 使用此函数来改变.</p>
<h2 id="Related">相关</h2>
<p><a href="SetWinDelay.htm">SetWinDelay</a>, <a href="WinExist.htm">WinExist</a>, <a href="WinActivate.htm">WinActivate</a>, <a href="RegExMatch.htm">RegExMatch</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>SetTitleMatchMode 1
<em>; OR:</em>
SetTitleMatchMode "RegEx"

SetTitleMatchMode "Slow"  <em>; Slow/Fast can be set independently of all the other modes.</em></pre>
</div>

</body>
</html>